home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Queues.h
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #pragma once
-
- #ifndef __QUEUES__
- #define __QUEUES__
-
- #ifndef __TYPES__
- #include "Types.h"
- #endif
-
- #ifndef __DIRECTOBJECT__
- #include "DirectObject.h"
- #endif
-
- /***********************************|****************************************/
-
- #pragma push
- #pragma segment Queue
-
- /***********************************|****************************************/
-
- class ostream;
- class TQueueItem;
-
- /***********************************|****************************************/
-
- class TQueue : public TDirectObject
- {
- public:
- virtual ~TQueue ();
-
- void* operator [] ( unsigned long ) const;
- void* Get ( unsigned long ) const;
-
- void Append ( void* ); // throws on memFullErr
- void Insert ( unsigned long, void* ); // throws on memFullErr
-
- Boolean Remove ( const void* ); // true if obj was found
- void* Remove ( unsigned long index = 1); // returns obj
- void RemoveAll ();
-
- Boolean Delete ( unsigned long ); // true if obj was found
- Boolean Delete ( void* ); // true if obj was found
- void DeleteAll ();
-
- unsigned long Count () const;
- unsigned long Find ( const void* ) const;
- Boolean IsValidIndex ( unsigned long ) const;
-
- void SetOwnsObjects ( Boolean = true );
- Boolean GetOwnsObjects () const;
-
- virtual ostream& operator >> ( ostream& ) const;
-
- protected: TQueue ( Boolean ownsObjects = true );
- void SetSize ( unsigned long objects );
- virtual void DeleteObject ( void* ) const;
-
- // These methods manage the queue 'items' -- the objects which make up
- // the linked list that is the queue.
- TQueueItem* NewQueueItem ( void * objectToQueue);
- void * ReturnQueueItem ( TQueueItem * queueItem );
-
- TQueueItem * GetQueueItem ( unsigned long index ) const;
-
-
- private: TQueue ( const TQueue& );
- TQueue& operator = ( const TQueue& );
-
- TQueueItem *fFirst;
- TQueueItem *fLast;
-
- TQueueItem *fSpareQueueItems;
-
- unsigned long fCount;
- Boolean fOwnsObjects;
- };
-
- /***********************************|****************************************/
-
- inline unsigned long TQueue::Count()const{return fCount;}
- inline Boolean TQueue::IsValidIndex(unsigned long i)const{return i>=1 && i<=fCount;}
- inline ostream& operator<<(ostream& s,const TQueue& l) {return l>>s;}
-
- #define DeclareQueue(OBJECT,QUEUE)\
- class QUEUE:public TQueue{public:QUEUE();virtual ~QUEUE();\
- Boolean Remove(const OBJECT* o){return TQueue::Remove((void*) o);};\
- OBJECT* Remove(unsigned long index = 1){return (OBJECT*)TQueue::Remove(index);};\
- OBJECT* operator[](unsigned long i)const{return (OBJECT*)TQueue::operator[](i);};\
- OBJECT* Get(unsigned long i)const{return (OBJECT*)TQueue::Get(i);};\
- virtual ostream& operator>>(ostream&) const;\
- protected: virtual void DeleteObject(void* o) const;}
-
- #define ImplementQueue(OBJECT,QUEUE,OWNS)\
- QUEUE::QUEUE():TQueue(OWNS){}QUEUE::~QUEUE(){if(GetOwnsObjects())DeleteAll();}\
- void QUEUE::DeleteObject(void* o)const{delete(OBJECT*)o;}\
- ostream& QUEUE::operator>>(ostream& s)const{s<<#QUEUE;return TQueue::operator>>(s);}
-
- /***********************************|****************************************/
-
- #pragma pop
-
- #endif
-